import "../../utils/store1/index.js";
//获取应用实例
const app = getApp()
// var validate=require('../../utils/validate/validate.js');

// import {Validate} from '../../utils/validate/validate.js';
import { paramsValidate } from 'paramsValidate.js';
import { Base } from '../../components/common/utils/base.js';


Page({
	data: {
		motto: 'Hello World',
		userInfo: {},
		hasUserInfo: false,
		canIUse: wx.canIUse('button.open-type.getUserInfo'),
		scrollHeight: 0,
		phoneNumber:'',
		banner:[
			{path: "http://image.chinalao.cn/upload/ad/2021/02/20210204601bb9ffe8d00.png",type:'img'},
			{path: "http://image.chinalao.cn/upload/ad/2021/03/20210324605ad53f01582.jpg",type:'img'},
			{path: "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4",type:'video'},
		],
		tabbar:{},

	},
	onLoad: function () {

		app.editTabbar();

		// wx.downloadFile({
		// 	url: 'http://vteipjuq.imwork.net/redpacketstart.mp3',
		// 	success: function(res) {
		// 	  console.log(res.tempFilePath)
		// 	  wx.playVoice({
		// 		filePath: res.tempFilePath,
		// 		success:function(res){
		// 			console.log('succ');
		// 			console.log(res);
		// 		},
		// 		complete: function (res) {
		// 		  console.log('playVoice res')
		// 		  console.log(res)
		// 		}
		// 	  })
		// 	//   wx.playBackgroundAudio({
		// 	// 	dataUrl: res.tempFilePath
		// 	//   })
		// 	}
		// })

		console.log(app.store.getState().text)
		app.store.setState({
			text: "我被修改了，呜呜...",
		});
		console.log(app.store.getState().text)





		var pvalidate = new paramsValidate();
		/**
		 * 调用参数验证
		 * 参数必须是json对象
		 * 函数循环调用
		 */
		// var errMsg=pvalidate.setScene('login').goCheck({uid:'123',category:'',id:''},'login');
		// var errMsg = pvalidate.setScene('login').goCheck({ uid: ['123'], category: '', password: '1', id: '1' });
		// if(errMsg){
		// console.log(errMsg);
		// return false;
		// }

		this.computeScrollViewHeight();



	},
	//事件处理函数
	bindViewTap: function () {
		wx.navigateTo({
			url: '../logs/logs'
		})
	},
	getUserInfo: function (e) {
		console.log(e)
		// app.globalData.userInfo = e.detail.userInfo
		// this.setData({
		// 	userInfo: e.detail.userInfo,
		// 	hasUserInfo: true
		// })
	},
	computeScrollViewHeight() {
		//创建节点选择器
		var query = wx.createSelectorQuery();
		//选择id
		var that = this;
		query.select('.ss').boundingClientRect(function (rect) {
			// console.log(rect)
			// console.log(rect.width)
		}).exec();
	},

	request(code) {
		return new Promise((resolve, reject) => {
			wx.request({
				url: 'http://local.appsv6.cn/api/mendiannologin/getopenidbycode?code=0530w71w3gJcRV2Q0W0w3wAiJB30w71l',
				method: 'get',
				data: {code:code},
				success: (res) => {
					resolve(res);
				}, fail: (err) => {
					reject(err) //失败调用reject
				}
			});
		})
	},
	async getWxLoginCode(e){
		console.log(e);
	},

	openList(){

		wx.navigateTo({
			url: '/pages/list/index'
		})
	},
	//get code
	getCode(e){
		console.log(e)

		wx.request({
			url:'https://api.weixin.qq.com/sns/jscode2session?appid=wx20c880d03db771df&secret=27423a03ef7ba669a7ab57a0cf2c453d&js_code='+e.detail.code+'&grant_type=authorization_code',
			method: 'get',
			success: (res) => {
				console.log(res)
				this.setData({
					sessionKey:res.data.session_key
				})
			}, fail: (err) => {

			}
		});
	},
	//解密手机号
	confirm(e){
		console.log(e)
		var obj={
			session_key:this.data.sessionKey,
			encrypted_data:e.detail.encryptedData,
			iv:e.detail.iv,
		}
		wx.request({
			url:'http://local.l56.cn/api/decryptmobilenumber',
			// url:'http://vteipjuq.imwork.net/api/decryptmobilenumber',
			method: 'post',
			data:obj,
			success: (res) => {
				console.log(res)
				console.log(res.data.phoneNumber)
				this.setData({
					phoneNumber:res.data.phoneNumber
				})
			}, fail: (err) => {

			}
		});
	},
})
